/*
* Portuguese eID Card API .NET Wrapper
*
* Written by Fernando Nunes (fernando.nunes@devscope.net)
* Copyright (c) 2009 DevScope Information Systems
*
* This library is free software; you can redistribute it and/or 
* modify it under the terms of the GNU Lesser General Public 
* License as published by the Free Software Foundation; either 
* version 2.1 of the License, or (at your option) any later version. 
* 
* This library is distributed in the hope that it will be useful, 
* but WITHOUT ANY WARRANTY; without even the implied warranty of 
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
* Lesser General Public License for more details. 
* 
* You should have received a copy of the GNU Lesser General Public 
* License along with this library; if not, write to the Free Software 
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA 
*/

#pragma once
#include "Stdafx.h"
#include "Certificate.h"
#include "Interop.h"

using namespace System;
using namespace DevScope::CartaoDeCidadao;

Certificate::Certificate(const PTEID_Certif& i)
{
	this->Bytes = gcnew array<Byte>(i.certifLength);
	this->Bytes = ArrayUnmanagedToManaged<Byte, unsigned char>((unsigned char*)i.certif, i.certifLength);
	this->Name = Interop::CStrToNetStr((char*)i.certifLabel);
}

Certificate::Certificate(String^ name, array<Byte>^ bytes)
{
	this->Bytes = bytes;
	this->Name = name;
}

PTEID_Certif Certificate::ToUnmanaged()
{
	PTEID_Certif personCertificate = PTEID_Certif();
	personCertificate.certifLength = ArrayManagedToUnmanaged<unsigned char, Byte>(this->Bytes, personCertificate.certif, this->Bytes->Length);
	Interop::copyNetToStr(this->Name, personCertificate.certifLabel);
	return personCertificate;
}
